/*************************************************************************************

Simple timer class to do some task at given tymes

**************************************************************************************/
#define SYNC_PERIOD 1000
#define NUM_EVENT_TYPES 2

#include <iostream>
using namespace std;

#using <system.dll>

using namespace System;
using namespace System::Timers;

#include <gl/glut.h>
#include "Scene.h"

public ref class ObjectPopper
{
public:
	static void run()
	{
		aTimer = gcnew System::Timers::Timer;

		aTimer->Elapsed += gcnew ElapsedEventHandler( ObjectPopper::OnTimedEvent );

		// Set the Interval to <SYNC_PERIOD> milliseconds
		aTimer->Interval = SYNC_PER;
		aTimer->Enabled = true;

		// Keep the timer alive until the end of the Demo method.
		// Included to prevent the JIT compiler from allowing 
		// aggressive garbage collection to occur before Demo
		// ends.
		GC::KeepAlive(aTimer);
	}

	static System::Timers::Timer^ aTimer;
//private:
	static int eventCount = -1;
	static bool calibrationOver = false;
	static int eventTriggered = -1;
	static int SYNC_PER = 1000;

	// signal for object translation and screen redraws at given time intervals.
	static void OnTimedEvent( Object^ /*source*/, ElapsedEventArgs^ /*e*/ )
	{
		eventCount++;
		eventTriggered = (++eventTriggered) % NUM_EVENT_TYPES;
		calibrationOver = ((eventCount / NUM_EVENT_TYPES) >= 
							NUM_CALIB_REGIONS_HORIZONTAL * NUM_CALIB_REGIONS_VERTICAL);
		glutPostRedisplay();
	}

};




